<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>天天生鲜-商品列表</title>
 <link rel="shortcut icon" href="images/copylogo.png">
 <link rel="stylesheet" href="css/reset.css">
 <link rel="stylesheet" href="css/main.css">
 <link rel="stylesheet" href="css/goods.css">
</head>

<body >
	<!-- 头部  -->
	<div class="header_con">
    	<div class="header">
    		<div class="welcome fl">欢迎来到天天生鲜</div>
    		<div class="fr" id="stu_name">
            	
             </div>  
    	</div>
    </div>
    
     <!-- 搜素框 -->
     <div class="search_bar clearfix">
        <a href="index.html" class="logo fl"><img src="images/logo.png"></a>
        <div class="search_con fl">
            <input type="text" placeholder="搜素商品" name="" class="input_text fl" id="inp">
            <input type="button" value="搜索" class="input_btn fr" onclick="find()">
        </div>
        <div class="guest_cart fr">
            <a href="front/page/cart.html" class="cart_name fl">我的购物车</a>
            <div class="goods_count fl" id="show_count">0</div>
        </div>
     </div>
     
    <!-- 全部商品分类 --> 
    <div class="navbar_con">
    	<div class="navbar clearfix">
        	<!-- 动态下拉框 -->
    		<div class="subnav_con fl">
            	<h1 class="fl">全商品分类</h1>
            	<span></span>
                <ul class="subnav" id="typeinfo">
                    
            	</ul>
            </div>
    		<ul class="navlist fl">
    			<li><a href="index.html">首页</a></li>
                <li class="interval">|</li>
                <li><a href="">手机生鲜</a></li>
                <li class="interval">|</li>
                <li><a href="">抽奖</a></li>
    		</ul>
    	</div>
    </div>
     
    <!-- 面包屑导航 --> 
    <div class="breadcrumb" id="breadcrumb">
     	<a href="index.html">全部分类</a>
        <span>&gt;</span>
        <a href="javascript:void(0)" id="gtype"></a>
     </div>
     
     <!-- 商品展示区域-->
     <div class="main_wrap clearfix">
     	<!-- 新品推荐 -->
        <div class="l_wrap fl clearfix">
        	<div class="new_goods">
            	<h3>新品推荐</h3>
            	<ul id="goods">
                	
                </ul>
            </div>
        </div>
        <!-- 热门类型查询 -->
        <div class="r_wrap fr clearfix">
        	<div class="sort_bar">
            	<a href="javascript:void(0);" id="normal" class="type active">默认</a>
                <a href="javascript:void(0);" id="price" class="type ">价格</a>
                <a href="javascript:void(0);" id="manUse" class="type ">人气</a>
            </div>
        	<ul class="goods_type_list clearfix show1" id="goodsinfo">
          		
            </ul>
			     <!-- 分页栏-->
			<div class="pagenation" id="page">
			<ul>
				<li><a href="#" class="">1</a></li>
			</ul>
				
			</div>
        </div>
   
     </div>
    <!-- 版权所有 -->
    <div class="footer">
    	<div class="foot_link">
        	<a href="#">关于我们</a> <span> | </span>
            <a href="#">联系我们</a> <span> | </span>
            <a href="#">招聘广告</a> <span> | </span>
            <a href="#">友情链接</a>
        </div>
    	<p>CopyRight &copy; 2019 嘟嘟嘟水果欢迎你的到来 All Rights Reserverd</p>
        <p>电话： </p>
    </div>
    <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
    <script>
    
    	var mno='null';
    	
    	//热门查询动态样式
		//给我们热门类型查询做点击事件
		$(".type").on("click",function(){
			//默认查询方式 
			var type = "id";
			//移除原来的active的样式
			$(".type").removeClass("active");
			//获取此时点击的对象的文本是什么
			var check = $(this).html();
			//判断
			if(check == "默认"){
				$("#normal").addClass("active");
			}
			if(check == "价格"){
				$("#price").addClass("active");
				type = "gprice"
			}
			if(check == "人气"){
				$("#manUse").addClass("active");
				type = "gsales"
			}
			//与后台交互 暂不处理
			/*
			$.post("url",{type:type},function(data){
				
			});
			*/
			//模拟动态页面
			
			
		})
		
		 
		function getPage(){
			$.post("goodsInfo/getPage", {tno:no},function(data){
				var str='<ul>';
				for(var i=1;i<=data;i++){
					if(i==1){
						str+='<li><a href="#" class="active">'+i+'</a></li>';
					}else{
						str+='<li><a href="#" class="">'+i+'</a></li>';
					}
					
				}
				str+='</ul>';
				$("#page").html(str);
			});
		}
		
		
	
		
		
		
		<!-- -->
		$.post("menberInfo/checkLogin", null , function(data){
			var str ='';
			
			if(!data.code){	
				mno=data.mno;
				str+='<div class="login_info fl">';
				str+='欢迎：<em>'+data.nickName+'</em>';
				str+='</div> ';
				geCarNnm(mno);
			} else {			
				str+='<div class="login_btn fl">';
				str+='<a href="login.html">登录</a>';
				str+='<span> | </span>';
				str+='<a href="register.html">注册</a>';
				str+='</div>';
			}
			str+='<div class="user_link fl">';
			str+='<span> | </span>';
			str+='<a href="front/page/user.html">用户中心</a>';
			str+='<span> | </span>';
			str+='<a href="front/page/cart.html">我的购物车</a>';
			str+='<span> | </span>';
			str+=' <a href="front/page/order.html">我的订单</a>  </div> ';
	    	$("#stu_name").html(str);
		}, "json");
		
		
		//发送ajax请求，得到类别
	    $.post("goodsInfo/findAll", null ,function(data){
	    	var tno = data[0].tno; 
	    	var typestr='';
	    	var newStr='';
	    	var goodstr='';
	    	var arr=["fruit","seafood","meet","egg","vegetables","ice"];
	    	var no='';
	    	var num=0;
	    	var start=0;
	    	var begin=0;
	    	var total=0;
	    	var pages=0;
	    	if(location.href.split("?").length>=2 ){
				  //容错处理，不这样做的话，如果没有参数，那么我们的服务器就会直接报错
				  var no=location.href.split("?")[1].split("=")[1];				  
			}else{
				location.href="index.html";
			}
	    	//getPage();
	    	for(var i=0;i<data.length;i++){
	    		if(data[i].tno==no){
		    		$("#gtype").html(data[i].tname);
		    		total++;//得到该商品种类总个数
	    		}
	    	}
			
	    	
	    	
	    	for(var i=0;i<data.length;i++){
	    		if(data[i].tno == tno){
	    			typestr+='<li><a href="goods.html?tno='+tno+'" class="'+arr[i]+'">'+data[i].tname +'</a></li>';
	    		 	tno++;
	    	 	}
	    		
	    		if(data[i].tno==no){
	    			goodstr+='<li> <a href="details.html?tno='+data[i].gno+'"><img src="'+data[i].pics+'"></a>';
	    			goodstr+='<h4><a href=""details.html?tno='+data[i].gno+'"">'+data[i].gname+'</a></h4>';
	    			goodstr+='<div class="operate">';
	    			goodstr+='<span class="prize">￥'+data[i].price+'</span>';
	    			goodstr+='<span class="unit">'+data[i].price+'/500g</span>';
	    			goodstr+='<a href="#" class="add_goods" title="加入购物车" onclick="add('+mno+','+data[i].gno+',1)"></a>';
	    			goodstr+='</div> </li>';	    			
	    			if(num<2){
		    			newStr+='<li> <a href="details.html?gno='+data[i].gno+'"><img src="'+data[i].pics+'"></a>';
			    		newStr+='<h4><a href="details.html?gno='+data[i].gno+'">'+data[i].gname+'</a></h4>';
			    		newStr+='<div class="prize">￥'+data[i].price+'</div> </li>';
		    		}
	    			num++;
	    		}
	    	 }
	    	 $("#goods").html(newStr);
	    	 $("#typeinfo").html(typestr);
	    	 $("#goodsinfo").html(goodstr);
	    },"json");
		
		
		//加入购物车
		function add(mno,gno,num){
			if(mno==null){
				alert("请先登录...");
				location.href="login.html";
				return;
			}
			$.post("cartInfo/checkCar", {mno:mno,gno:gno},function(data){
				if(data.length<=0){//购物车不存在该商品
					$.post("cartInfo/add", {mno:mno,gno:gno,num:num},function(data){
						if(data>0){//添加成功
							alert("新商品,添加成功...");
							geCarNnm(mno);
						}
					},"text");
				} else {//购物车中已经存在该商品,只需要加数量就行了
					$.post("cartInfo/update", {num:num,cno:data},function(data){
						if(data>0){
							alert("添加成功...");
						}
					},"text");
				}				
			},"text");
		}
		
		function geCarNnm(mno){
			$.post("cartInfo/finds", {mno:mno}, function(data){
				var numStr=data.length;		    	
				$("#show_count").html(numStr);
			},"json");	
		}
		
		function find(){
			var str=$("#inp").val();
			$.post("goodsInfo/find",{str:str},function(data){
				console.log(data);
				if(data==null){
					alert("抱歉,没有该商品...");
					console.log("抱歉,没有该商品...");
				}else{					
					location.href="details.html?gno="+data.gno;
				}
			},"json");
		}
		
		function findByTno(tno,start){
			$.post("goodsInfo/findByTno",{tno:tno,Start:start},function(data){
				var goodstr='';
				for(var i=0;i<data.length;i++){
					goodstr+='<li> <a href="details.html?tno='+data[i].gno+'"><img src="'+data[i].pics+'"></a>';
	    			goodstr+='<h4><a href=""details.html?tno='+data[i].gno+'"">'+data[i].gname+'</a></h4>';
	    			goodstr+='<div class="operate">';
	    			goodstr+='<span class="prize">￥'+data[i].price+'</span>';
	    			goodstr+='<span class="unit">'+data[i].price+'/500g</span>';
	    			goodstr+='<a href="#" class="add_goods" title="加入购物车" onclick="add('+mno+','+data[i].gno+',1)"></a>';
	    			goodstr+='</div> </li>';	
				}
		    	 $("#goodsinfo").html(goodstr);
			},"json");
		}
	</script>
</body>
</html>

  
